package com.zy.springboot.mall_spring_boot.controller.sys;

import com.zy.springboot.mall_spring_boot.common.Counts;
import com.zy.springboot.mall_spring_boot.controller.common.CommonController;
import com.zy.springboot.mall_spring_boot.beans.MUser;
import com.zy.springboot.mall_spring_boot.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/sys/user")
public class UserController extends CommonController{
//    @Resource
    @Autowired
    private IUserService userService;

    @RequestMapping("/{path}")
    public String login(@PathVariable("path") String path){
        return path;
    }



    @RequestMapping("/logOut")
    public String logOut(HttpServletRequest request){
        request.getSession().invalidate();
        log.debug("logOut");
        return "login";
    }
    /**
     * @Author GongXl
     * @Description
     * @Date 025 9:17
     * @Param [request, userName, mUser]
     * @return java.lang.String
    **/
    @RequestMapping(value="/login_mall")
    public String login_mall(HttpServletRequest request, String userName,MUser mUser){
        log.debug("login_mall");
        mUser.setStatus(Counts.USER_STATUS_ENABLE);
        //用存在，将放session,
        System.out.println("longin#####"+mUser);
        //从数据库查 user pass
        MUser mUserTemp = userService.queryUser(mUser);
        if(null != mUserTemp){
            request.getSession().setAttribute("mUser",mUserTemp);
            return "index";
        }
        request.setAttribute("msg","用户不存在");
        return "login";
    }



}
